package com.xiaohong.file.feign;

import entity.Result;
import feign.form.spring.SpringFormEncoder;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import feign.codec.Encoder;

/**
 * @author xiaohong
 * @Description
 * @date 2020/10/27 0027 23:41
 */
@FeignClient(name="file-service")
@RequestMapping("/file")
public interface FileFeign {

    @PostMapping(value = "/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    Result uploadFile(@RequestPart(value = "file") MultipartFile file);

    /**
     * 引用配置类MultipartSupportConfig.并且实例化
     */
    class MultipartSupportConfig {
        @Bean
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder();
        }
    }

    /**
     * 文件下载
     * @param fileUrl
     * @param downloadUrl
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/download")
    Result downloadFile(@PathVariable(value = "fileUrl") String fileUrl,@PathVariable(value = "downloadUrl") String downloadUrl);

    /**
     * 文件删除
     * @param fileUrl
     * @return
     * @throws Exception
     */
    @DeleteMapping(value = "/delete")
    Result deleteFile(@RequestParam(value = "fileUrl") String fileUrl);

}
